package chaoyue.study;

import java.util.Random;

/**
 * 线程工具类
 * 抽取sleep部分代码，方便整体逻辑的阅读
 */
public class ThreadUtils {

    public static void sleep() {
        sleep(3000);
    }

    public static void sleep(int milliseconds) {
        try {
            Thread.sleep(milliseconds);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void sleepRandom() {
        sleepRandom(5000);
    }

    public static void sleepRandom(int milliseconds) {
        try {
            Thread.sleep(new Random().nextInt(milliseconds));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
